package cn.lyh;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.po.TableFill;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

import java.util.ArrayList;
import java.util.List;

// 代码自动生成器
public class GenCode {

    public static void main(String[] args) {
        // 需要构建一个代码自动生成器对象
        AutoGenerator autoGenerator = new AutoGenerator();
        // 再配置策略
        autoGenerator.setGlobalConfig(new GlobalConfig()
            .setOutputDir(System.getProperty("user.dir") + "/src/main/java")
            .setAuthor("liangyihui")
            .setOpen(false)
            .setFileOverride(false)
            .setServiceName("%sService")
            .setIdType(IdType.ID_WORKER)
            .setDateType(DateType.ONLY_DATE)
            .setSwagger2(true))

            .setDataSource(new DataSourceConfig()
            .setUrl("jdbc:mysql://localhost:3306/filemanage?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true")
            .setDriverName("com.mysql.cj.jdbc.Driver")
            .setUsername("root")
            .setPassword("root")
            .setDbType(DbType.MYSQL))

            .setPackageInfo(new PackageConfig()
            .setParent("cn.lyh")
            .setEntity("entity")
            .setMapper("mapper")
            .setService("iservice")
            .setController("icontroller"))

            .setStrategy(
             new StrategyConfig()
            .setInclude("tb_file") ////////////////////////////////////////要生成的表名///////////////////////////////////////////////////
            .setTablePrefix("tb_")
            .setNaming(NamingStrategy.underline_to_camel)//驼峰命名
            .setColumnNaming(NamingStrategy.underline_to_camel)
            .setEntityLombokModel(true)
            .setRestControllerStyle(true)
            .setControllerMappingHyphenStyle(true)
            );

        autoGenerator.execute();

    }

}
